
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for password_reminder.
	''' </summary>
	Public Partial Class password_reminder
		Inherits BaseWebPage

		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.PASSWORD_REMINDER_PAGE;

			' init page from XML
			Me.initPageTitles(Constants.PASSWORD_REMINDER, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			lblMessage.Visible = False
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.cvUserExists.ServerValidate, AddressOf Me.cvUserExists_ServerValidate

		End Sub
#End Region

		Private Sub cvUserExists_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim usr As User = Users.GetUserByEmail(txtEmailRemind.Text)
			If usr = Nothing Then
				args.IsValid = False
			Else
				args.IsValid = True
			End If
		End Sub

		Protected Sub lbSendPassword_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If Me.IsValid Then
				Dim usr As BO.User = Users.GetUserByEmail(txtEmailRemind.Text.Trim())
				If usr <> Nothing Then
					Dim newPass As String = Users.GetRandomPassword()

					usr.Password = newPass
					usr.Save()

					Users.SendPassResetEmail(Constants.APPLICATION_URL + "/" + Constants.CHANGE_PASSWORD, usr)

					lblMessage.Text = (Me.GetPageConstText(htPageConstants, "CONST_MsgPassSent_TEXT")).Replace("[PARAM]", txtEmailRemind.Text.Trim())
						'litEnterEmail.Visible = false;
						'litPleaseEnter.Visible = false;
						'lbSendPassword.Visible = false;
					lblMessage.Visible = True
				End If
			End If
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class
End Namespace






